//
//  ByPersonalViewModel.m
//  jmsfhz_ios
//
//  Created by pro on 16/8/3.
//  Copyright © 2016年 pro. All rights reserved.
//

#import "ByPersonalViewModel.h"

#import "ByNetUserApi.h"    // 用户接口

@implementation ByPersonalViewModel

/** 用户更新 */
- (void)update:(ByNetParamsModel *)params {

    void (^failure)(ByNetBaseResult *result) = nil;
    
    if([self.updateDelegate respondsToSelector:@selector(updateFailure:)]) {
        
        failure = ^(ByNetBaseResult *result){
            [self.updateDelegate updateFailure:result];
        };
    }
    
    [ByNetUserApi updateUserInfo:params success:^(ByNetBaseResult *result) {
        if (self.updateDelegate) {
            [self.updateDelegate updateSuccess:result];
        }
    } failure:failure];
}

/** 上传头像 */
- (void)uploadIcon:(ByNetParamsModel *)params {
    
    void (^failure)(ByNetBaseResult *result) = nil;
    
    if([self.uploadIconDelegate respondsToSelector:@selector(uploadIconFailure:)]) {
        
        failure = ^(ByNetBaseResult *result){
            [self.uploadIconDelegate uploadIconFailure:result];
        };
    }
    
    [ByNetUserApi iconUpload:params.iconImage success:^(ByNetBaseResult *result) {
        if (self.uploadIconDelegate) {
            [self.uploadIconDelegate uploadIconSuccess:result];
        }
    } failure:failure];
}

/** 上传头像 */
- (void)authenticate:(ByNetParamsModel *)params {
    
    void (^failure)(ByNetBaseResult *result) = nil;
    
    if([self.authenticateDelegate respondsToSelector:@selector(AuthenticateFailure:)]) {
        
        failure = ^(ByNetBaseResult *result){
            [self.authenticateDelegate AuthenticateFailure:result];
        };
    }
    
    [ByNetUserApi authenticationUpload:params.iconImage success:^(ByNetBaseResult *result) {
        if (self.authenticateDelegate) {
            [self.authenticateDelegate AuthenticateSuccess:result];
        }
    } failure:failure];
}
@end
